import os
import sys
import json
import requests
import sseclient

def get_stream_result(url, payload, headers, is_stream=True):
    req = requests.get(url, params=payload, headers=headers, stream=is_stream)
    client = sseclient.SSEClient(req)
    for event in client.events():
        jsn = json.loads(event.data)
        idx = jsn['idx']
        text = jsn['text']
        timestamp = jsn['timestamp']
        print(idx, text, timestamp)

url = "http://localhost:8080/stream"
headers = {'Accept': 'text/event-stream'}
payload = dict()
payload['key'] = 'value'
get_stream_result(url, payload, headers)
